/*
*********************************************************************************************************
*                                 STM32F4 Driver Platform
*
*                             (c) Copyright 2015; DL-Laike
*
*                   All rights reserved.  Protected by international copyright laws.
*                   Knowledge of the source code may not be used to write a similar
*                   product.  This file may only be used in accordance with a license
*                   and should not be redistributed in any way.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                        the BSP of CAN Communication
*                             ST Microelectronics STM32 with the STM32F407IGT6
*
* Filename      : bsp_CAN.h
* Version       : V1.0.0
* Programmer(s) : ZhangYu
*********************************************************************************************************
*/
#ifndef BSP_CAN_H_
#define BSP_CAN_H_

#define CAN_SEND_RETRY_CNT			(3)

#define	CAN1_MSG_TYPE				(1)	//1-> Extend Can ID, 0-> stand Can ID
#define CAN2_MSG_TYPE				(1)	//1-> Extend Can ID, 0-> stand Can ID

//----------------CAN1(RX -> PA11  TX -> PA12)-----------------------------
#define CAN1_CLK                    RCC_APB1Periph_CAN1
#define CAN1_RX_PIN                 GPIO_Pin_11
#define CAN1_TX_PIN                 GPIO_Pin_12
#define CAN1_GPIO_PORT              GPIOA
#define CAN1_GPIO_CLK               RCC_AHB1Periph_GPIOA
#define CAN1_AF_PORT                GPIO_AF_CAN1
#define CAN1_RX_SOURCE              GPIO_PinSource11
#define CAN1_TX_SOURCE              GPIO_PinSource12

//-----------------CAN2(RX -> PB5  TX -> PB6)----------------------------
#define CAN2_CLK                    (RCC_APB1Periph_CAN1 | RCC_APB1Periph_CAN2)
#define CAN2_RX_PIN                 GPIO_Pin_5
#define CAN2_TX_PIN                 GPIO_Pin_6
#define CAN2_GPIO_PORT              GPIOB
#define CAN2_GPIO_CLK               RCC_AHB1Periph_GPIOB
#define CAN2_AF_PORT                GPIO_AF_CAN2
#define CAN2_RX_SOURCE              GPIO_PinSource5
#define CAN2_TX_SOURCE              GPIO_PinSource6

/*----------CAN Message define in the STD library-------------
typedef struct
{
  uint32_t StdId;  //!< Specifies the standard identifier.
                        //This parameter can be a value between 0 to 0x7FF.

  uint32_t ExtId;  //!< Specifies the extended identifier.
                        //This parameter can be a value between 0 to 0x1FFFFFFF.

  uint8_t IDE;     //!< Specifies the type of identifier for the message that
                        //will be received. This parameter can be a value of
                        //@ref CAN_identifier_type

  uint8_t RTR;     //!< Specifies the type of frame for the received message.
                        //This parameter can be a value of
                        //@ref CAN_remote_transmission_request

  uint8_t DLC;     //!< Specifies the length of the frame that will be received.
                        //This parameter can be a value between 0 to 8

  uint8_t Data[8]; //!< Contains the data to be received. It ranges from 0 to
                        //0xFF.

  uint8_t FMI;     //!< Specifies the index of the filter the message stored in
                        //the mailbox passes through. This parameter can be a
                        //value between 0 to 0xFF
} CanRxMsg;
--------------------------------------------------------*/

//-------------------function declartion------------------
void BSP_CAN1_Config(uint16_t bandrate);
void BSP_CAN2_Config(uint16_t bandrate);
uint32_t BSP_Can1WriteData(uint8_t msgType, uint32_t CanID, uint8_t *pData, uint8_t Len);
uint32_t BSP_Can2WriteData(uint8_t msgType, uint32_t CanID, uint8_t *pData, uint8_t Len);

#endif /* BSP_CAN_H_ */
